//定义关于counter 的store

import { defineStore } from 'pinia/dist/pinia'
import useUser from '../stores/user'
const useCounter = defineStore('counter', {
  state: () => ({
    count: 100,
    users: [
      { id: 111, name: '张三' },
      { id: 222, name: '李四' },
      { id: 333, name: '王五' },
    ],
  }),
  getters: {
    // doubleCounter:(state)=>state.count*2
    doubleCounter(state) {
      return state.count * 2
    },
    doubleCounterAddone() {
      return this.doubleCounter + 1
    },
    // getters也支撑返回一个函数
    getUserId(state) {
      return function (id) {
        return state.users.find((item) => item.id === id)
      }
    },
    //getters中用到了另外一个getter
     showMessage(state){
      const useStore=useUser()
      //获取自己信息
      //拼接信息
      return `name:${useStore.name}---count:${state.count}`

     }
  },
  actions:{
    increment(num){
      console.log(num) 
      this.count+=num
    }
  }
})
export default useCounter
